import { createWebHashHistory, createRouter } from "vue-router";
import HelloWorld from "../components/Home/login.vue"
import Home from '../components/Home/HomeHeader.vue'
import staff from '../components/admin/staff.vue'
import role from '../components/admin/role.vue'
import resource from '../components/admin/resource.vue'
// import user from "../components/oneuser.vue"
import addrole from "../components/admin/addrole.vue";
import addstaff from '../components/admin/addstaff.vue'
import firsthome from '../components/Home/firsthome.vue'
import updaterole from "../components/admin/updaterole.vue"
import resource_exp from "../components/admin/resource_exp.vue"
import userlist from "../components/user/userlist.vue";
import adduser from "../components/user/adduser.vue"
import addworkflow from "../components/admin/addworkflow.vue"
import addworkflow2 from "../components/admin/addworkflow2.vue"
import check_work from "../components/workflow/check_work.vue";
import workflow_one from "../components/workflow/workflow_one.vue";
import Workflow_role from "../components/admin/workflow_role.vue";
import work_approval from "../components/admin/work_approval.vue";
import approval from "../components/admin/approval.vue"
import Application from "../components/workflow/application.vue";
const routes = [
    {
        path: "/",
        name: "Login",
        component: HelloWorld
    },
    {

        path: '/home',
        name: 'Home',
        component: Home,
        children: [
            {
                path: '/staff',
                name: 'staff',
                component: staff,
                meta: {
                    title: 'page1'
                }
            },
            {
                path: '/role',
                name: 'role',
                component: role
            },
            {
                path: '/resource',
                name: 'resource',
                component: resource
            },
            {
                path: "/addrole",
                name: "addrole",
                component: addrole
            },
            {
                path: '/addstaff',
                name: 'addstaff',
                component: addstaff
            },
            {
                path: '/firsthome',
                name: 'firsthome',
                component: firsthome
            },
            {
                path: '/updaterole',
                name: 'updaterole',
                component: updaterole
            },
            {
                path: '/resource_exp',
                name: 'resource_exp',
                component: resource_exp
            },
            {
                path: '/userlist',
                name: 'userlist',
                component: userlist
            },
            {
                path: '/adduser',
                name: 'adduser',
                component: adduser
            },
            {
                path: '/addworkflow',
                name: 'addworkflow',
                component: addworkflow
            },
            {
                path: '/addworkflow2',
                name: 'addworkflow2',
                component: addworkflow2
            },
            {
                path: '/check_work',
                name: 'check_work',
                component: check_work
            },
            {
                path: '/workflow_one',
                name: 'workflow_one',
                component: workflow_one
            },
            {
                path: '/workflow_role',
                name: 'workflow_role',
                component: Workflow_role
            },
            {
                path: '/work_approval',
                name: 'work_approval',
                component: work_approval
            },
            {
                path: '/approval',
                name: 'approval',
                component: approval
            },
            {
                path: '/application',
                name: 'application',
                component: Application
            }
        ]
    },
]
const router = createRouter({
    history: createWebHashHistory(),
    routes
})
// router.beforeEach((to, from, next) => {
//     const wlist = ["/"]
//     console.log(wlist.includes(to.path))
//     if (wlist.includes(to.path)){
//         next()
//     }
//     else{
//         const token = localStorage.getItem('jwt_token'); // 获取 token
//         console.log(token)
//         if (token) {
//                  // 如果有 token，检查用户是否有权限访问该路由
//               const menulist = JSON.parse(localStorage.getItem("menulist"))
//               console.log(menulist)
//               const urllist=[]
//               for (let i = 0; i < menulist.length; i++) {
//                   console.log(menulist[i]["url"]); 
//                   // 打印每个 URL
//                   urllist.push(menulist[i]["url"])
//                 }
//                 console.log(urllist)
//               if (urllist.includes(to.path) || to.path == "/home" || to.path == "/check_work" ){
//                   next(); // 用户有权限，继续
//               }else {
//                 alert("没有访问权限，请重新登录")
//                 next("/")
//               }
//         }
//         }
//     }
// )
// router.beforeEach((to, from, next) => {
//     var reslist = ['/']
//     if (reslist.indexOf(to.path) == -1) {
//         var token = localStorage.getItem('jwt_token')
//         if (token) {
//             const menulist = JSON.parse(localStorage.getItem("menulist"))
//             const urllist=[]
//             console.log(menulist)
//             for (let i = 0; i < menulist.length; i++) {
//                 console.log(menulist[i]["url"]); 
//                 // 打印每个 URL
//                 urllist.push(menulist[i]["url"])
//               }
//               console.log(urllist)
//             if (urllist.includes(to.path) || to.path == "/home" ){
//                 next(); // 用户有权限，继续
//             }else {
//               alert("没有访问权限，请重新登录")
//               next("/")
//             }
//         }
//     }
// })




export default router